/*
 * @lc app=leetcode.cn id=704 lang=javascript
 *
 * [704] 二分查找
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number}
 */
var search = function (nums, target) {
  let l = 0;

  let r = nums.length - 1;
  //左闭右闭

  while (l <= r) {
    const middle = Math.floor((l + r) / 2);

    if (nums[middle] > target) {
      r = middle - 1;
    }
    if (nums[middle] < target) {
      l = middle + 1;
    }

    if (nums[middle] === target) {
      return middle;
    }
  }

  return -1;
};
// @lc code=end

console.log((0 + 1) >>> 1);
